<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <title>橘子网课答案查询 - 最便捷的大学网课答案在线查询网站</title>
    <meta name="productIds" content="橘子网课答案查询,橘子网课查题小程序,橘子校园查题公众号"/>
    <meta itemprop="description" name="description"
          content="橘子网课答案查询(www.orangewangke.cn)提供简单便捷的大学超星尔雅、知到智慧树网课答案查询服务。让您的大学网课查题更简单。"/>
    <meta itemprop="name" content="橘子网课答案查询 - 最便捷的网课查询网站"/>
    <meta itemprop="image" content="/images/wechat.png"/>
    <meta property="og:image" content="/images/wechat.png"/>
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/me/style.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/me/1.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css"/>
    <link rel="shortcut icon" href="/favicon.ico">
</head>
<body style="height: auto">
<div class="header">
    <ul class="layui-nav">
        <li class="layui-nav-item">
            <a th:href="@{/}">返回查题首页</a>
        </li>
    </ul>
</div>
<div class="container" style="top:100px;">
    <div class="main">
        <div class="content-body">
            <!-- 左侧 -->
            <div class="content-left">
                <div class="avatar">
                    <img src="/layui/images/wechat.png" alt="">
                </div>
                <div class="device">
                    <p class="name">橘子查题</p>
                    <p class="qq">更多答案请关注【橘子校园查题】微信公众号查询</p>
                </div>
            </div>
            <!-- 右侧 -->
            <div class="content-right">
                <div class="content index">
                    <div class="index-box">
                        <div class="container">
                            <div class="main">
                                <div class="content-body">
                                    <!-- 左侧 -->

                                    <!-- 右侧 -->
                                    <div class="content-right">
                                        <div class="title">商品列表</div>
                                        <div class="content">
                                            <table class="layui-table">
                                                <thead>
                                                <tr>
                                                    <th>商品名称</th>
                                                    <th>单价</th>
                                                    <th>折扣</th>
                                                    <th>库存</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr th:each="product : ${products}">
                                                    <td><span th:text="${product.name}"></span><span class="layui-badge"
                                                                                                     th:if="${product.discount!=1.0}"
                                                                                                     style="margin-left: 3px;">Hot</span>
                                                    </td>
                                                    <td th:text="${product.price}"></td>
                                                    <td th:text="${product.discount}"></td>
                                                    <td><span th:text="${product.nums}"></span><span
                                                            class="layui-badge layui-bg-orange"
                                                            th:if="${product.nums<20}"
                                                            style="margin-left: 3px;">少量库存</span></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                            <div class="content-box">
                                                <div class="content-key">
                                                    <select id="product" name="productId" lay-verify="required">
                                                        <option value="" selected disabled>请选择商品</option>
                                                        <option th:value="${product.id}" th:each="product : ${products}"
                                                                th:text="${product.name}"></option>
                                                    </select>
                                                </div>
                                                <button type="submit" id="ajax_key">购买</button>
                                            </div>
                                            <div id="tips"></div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>

                    </div>
                </div>
            </div>
            <div class="index-link">
                <div class="link-title"><h3>友情链接</h3></div>
                <ul>
                    <li><a href="http://wpa.qq.com/msgrd?v=3&uin=1950661299&site=qq&menu=yes" title="" target="_blank">联系客服</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <footer>
        <span class="footer-left">©&nbsp;2020 Copyright&nbsp;<a href="http://www.orangewangke.cn"
                                                                title="">橘子网课查题</a></span>
        <span class="footer-right"><a rel="nofollow" href="http://www.beian.miit.gov.cn/" target="_blank" title="">粤ICP备xxxx号</a>
		    </span>
        <!--        <span class="footer-right"><a rel="nofollow" href="http://www.beian.miit.gov.cn/" target="_blank" title="">粤ICP备19149910号</a>-->
        <!--		    </span>-->
    </footer>
</div>
<script src="/layui/jquery-3.0.0.min.js"></script>
<script src="/layui/layui.js"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['layer', 'form', 'element', 'jquery'], function () {
        const layer = layui.layer,
            $ = layui.jquery,
            form = layui.form,
            element = layui.element;

        $('#ajax_key').click(function () {

            var productId = $('#product').val();
            if (productId === '' || productId == null) {
                layer.msg("请选择商品", {
                    icon: 2,
                    time: 1000
                });
                return false;
            }
            layer.prompt({title: '购买数量'}, function (val, index) {
                if (val < 0 || val > 10) {
                    layer.msg("购买数量限制1-10件", {
                        icon: 2,
                        time: 1000
                    });
                    return false;
                }
                layer.close(index);
                layer.load();
                var header = {
                    "Authorization": localStorage.getItem("Authorization"),
                    "RefreshToken": localStorage.getItem("RefreshToken")
                }
                if ([[${user}]] == null)
                    header = {}
                $.ajax({
                    url: "product/" + productId + "?nums=" + val,
                    type: "GET",
                    headers: header,
                    success: function (res) {
                        layer.closeAll("loading");
                        if (res.code !== 1) {
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 1000
                            });
                        } else {
                            location.href = res.data;
                        }
                        console.log(res)
                    },
                    error: function () {
                        layer.closeAll("loading");
                        layer.msg('服务器请求失败', {icon: 2, shade: [0.5, '#000000'], shadeClose: true, time: 1000});
                        return false;
                    }
                });
            });


        });


    })
</script>
</body>
</html>